#!/bllin/bash

while getopts ":u:p:h:" opt
do
    case $opt in
        h)
        HOST_NAME=$OPTARG
        echo -e "\033[40;37m 您输入的主机选项$HOST_NAME\033[0m"
        ;;
        u)
        USER_NAME=$OPTARG
        echo -e "\033[40;37m 您输入的用户名:$USER_NAME\033[0m"
        ;;
        p)
        PASSWORD=$OPTARG
        echo -e "\033[40;37m 您输入的密码:$PASSWORD\033[0m"
        ;;
        ?)
        echo -e "\033[40;37m 未知参数,你可以这样使用 : sh upgrade.sh -s ~/${WORK_USER}/system-init -btrue -nhello -v3.0.1.3\033[0m"
        exit 1;;
    esac
done

expect <<EOF
  set timeout 50
  spawn ssh-copy-id -i ${HOME}/.ssh/id_rsa.pub ${USER_NAME}@${HOST_NAME}
  expect {
    "yes/no" { send "yes\n";exp_continue } 
    "*password:" { send "${PASSWORD}\n" }
  }
  expect eof
EOF
